package seminar;

import org.apache.log4j.Logger;

/**
 * A lecture event (combination of lecture and room)
 * @author Johannes Degler
 *
 */
public class LectureEvent {

	private final static Logger log = Logger.getLogger(LectureEvent.class);

	private final Lecture lecture;

	private final Room room;

	/**
	 * New lecture event
	 * @param lecture The lecture
	 * @param room The room
	 */
	public LectureEvent(final Lecture lecture, final Room room){
		this.lecture = lecture;
		this.room = room;

		LectureEvent.log.debug("New lecture event " + this);
	}



	@Override
	public boolean equals(final Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (this.getClass() != obj.getClass())
			return false;
		final LectureEvent other = (LectureEvent) obj;
		if (this.lecture == null) {
			if (other.lecture != null)
				return false;
		} else if (!this.lecture.equals(other.lecture))
			return false;
		if (this.room == null) {
			if (other.room != null)
				return false;
		} else if (!this.room.equals(other.room))
			return false;
		return true;
	}

	/**
	 * Get the lecture
	 * @return Lecture
	 */
	public Lecture getLecture() {
		return this.lecture;
	}


	/**
	 * Get the room
	 * @return Room
	 */
	public Room getRoom() {
		return this.room;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ (this.lecture == null ? 0 : this.lecture.hashCode());
		result = prime * result
				+ (this.room == null ? 0 : this.room.hashCode());
		return result;
	}



	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("LectureEvent [");
		sb.append(this.lecture);
		sb.append(", ");
		sb.append(this.room.getDescription());
		sb.append(']');

		return sb.toString();
	}
}
